package com.qxsx.midi.activity.exam;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.qxsx.midi.R;
import com.qxsx.midi.activity.base.BaseActivity;
import com.qxsx.midi.activity.home.MusicDetailsActivity;
import com.qxsx.midi.utils.CustomProgress;
import com.qxsx.midi.utils.MyNet;
import com.qxsx.midi.utils.callBackJsonArray;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Administrator on 2015/10/16.
 */
public class ExamWaitFailActivity extends BaseActivity {
    private CustomProgress customProgress;

    private TextView tv_subject, tv_grade, tv_address, tv_time, tv_phone, tv_content, tv_point;
    String id;
    String major_name, grade_num, exam_site_name, exam_time, tel, detail, grade_score, monitor_teacher_id, monitor_give_score;
    private ImageView iv_img;
    private Button btn_evaluate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wait_fail);
        setTitle("考试完成");
        setNavBtn(R.mipmap.back, 0);
        Intent intent = getIntent();
        id = intent.getStringExtra("id");//得到ID
        findById();

    }

    @Override
    protected void onResume() {
        super.onResume();
        examwait();
    }

    private void examwait() {
        customProgress = CustomProgress.show(ExamWaitFailActivity.this, "正在加载中....", true, null);

        JSONObject object = new JSONObject();
        JSONArray array = new JSONArray();

        try {
            object.put("exam_id", id);
            array.put(object);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        MyNet.doPostJsonArray("8012", array, new callBackJsonArray() {
            @Override
            public void run(Object code, Object message, JSONArray array) {
                if (array == null) {
                    return;
                }

                try {
                    JSONObject object1 = array.getJSONObject(0);

                    object1.getString("id");
                    major_name = object1.getString("major_name");
                    grade_num = object1.getString("grade_num");
                    exam_site_name = object1.getString("exam_site_name");
                    exam_time = object1.getString("exam_time");
                    object1.getString("state_code");
                    object1.getString("state_msg");
                    object1.getString("cost");
                    monitor_teacher_id = object1.getString("monitor_teacher_id");
                    monitor_give_score = object1.getString("monitor_give_score");

                    tel = object1.getString("tel");
                    grade_score = object1.getString("grade_score");
                    //detail = object1.getString("detail");
                    if (major_name.toString().equals("电吉他")) {
                        iv_img.setImageResource(R.mipmap.wait_j);
                    } else if (major_name.toString().equals("电贝司")) {
                        iv_img.setImageResource(R.mipmap.wait_b);

                    } else if (major_name.toString().equals("爵士鼓")) {
                        iv_img.setImageResource(R.mipmap.wait_g);
                    } else if (major_name.toString().equals("音乐基础")) {
                        iv_img.setImageResource(R.mipmap.wait_y);
                    }
                    tv_subject.setText(major_name);
                    tv_grade.setText(grade_num+"级");
                    tv_address.setText(exam_site_name);
                    tv_time.setText(exam_time);
                    tv_phone.setText(tel);
                    tv_content.setText(detail);
                    tv_point.setText(grade_score);
                    if (monitor_give_score.toString().equals("0")) {
                        btn_evaluate.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                               // startActivity(new Intent(ExamWaitFailActivity.this, AssessTeachertActivity.class));
                                Intent it = new Intent(ExamWaitFailActivity.this, AssessTeachertActivity.class);
                                it.putExtra("id", monitor_teacher_id);//传递商家ID
                                it.putExtra("exam_id", id);//传递商家ID
                                startActivity(it);
                            }
                        });
                    } else {
                        btn_evaluate.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent it = new Intent(ExamWaitFailActivity.this, AssessTeachertSureActivity.class);
                                it.putExtra("id", monitor_teacher_id);//传递商家ID
                                it.putExtra("exam_id", id);//传递商家ID
                                startActivity(it);
                            }
                        });
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                customProgress.dismiss();

            }
        });
    }


    private void findById() {
        iv_img = (ImageView) findViewById(R.id.iv_img);
        tv_subject = (TextView) findViewById(R.id.tv_subject);
        tv_grade = (TextView) findViewById(R.id.tv_grade);
        tv_address = (TextView) findViewById(R.id.tv_address);
        tv_time = (TextView) findViewById(R.id.tv_time);
        tv_phone = (TextView) findViewById(R.id.tv_phone);
        tv_content = (TextView) findViewById(R.id.tv_content);
        tv_point = (TextView) findViewById(R.id.tv_point);

        btn_evaluate = (Button) findViewById(R.id.btn_evaluate);


    }

    @Override
    protected void HandleTitleBarEvent(TitleBar component, View v) {
        switch (component) {
            case LEFT:
                finish();
                break;
        }
    }


}
